package com.example.graduation.controller.admin.user;

import com.example.graduation.entity.pojo.User;
import com.example.graduation.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Jeffery
 */
@RequestMapping("/admin/user")
@Controller
@Slf4j(topic = "AdminUserController")
@Api(tags = "管理员管理user")
public class AdminUserController {
    private static final int PAGE_SIZE = 10;

    @Resource
    private UserService userService;

    /**
     * 查询所有用户（包含逻辑删除）
     *
     * @param pageNumber 当前页数
     * @return 分页信息
     */
    @PostMapping("/userList/{pageNumber}")
    public String userList(Model model,
                           @PathVariable("pageNumber") int pageNumber) {
        PageHelper.startPage(pageNumber, PAGE_SIZE);
        List<User> userList = userService.list();
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        model.addAttribute("pageInfo", pageInfo);
        return "";
    }


}
